package com.web.util.string;

import java.util.StringTokenizer;

public class StringUtil {

	public static boolean isNullOrEmpty(String string) {
		return (string==null || string.length()==0);
	}
	
	public static String replace(String string, String pattern, String replaceBy) {
		
		int start = 0;
        int index = 0;
        StringBuffer result = new StringBuffer();
    
        while ((index = string.indexOf(pattern, start)) >= 0) {
            result.append(string.substring(start, index));
            result.append(replaceBy);
            start = index + pattern.length();
        }
        result.append(string.substring(start));
        return result.toString();
		
	}
	
	public static String formalizeCase(String string) {
		
		StringTokenizer strings = new StringTokenizer(string);
		String newString = "";
		while (strings.hasMoreTokens()) {
			String str = strings.nextToken();
			str = str.substring(0, 1).toUpperCase() + str.substring(1);
			newString += str + " ";
		}
		newString = newString.trim();		
		
		return newString;
	}
	
	public static String mask(String string, char c) {
		
		String string1 = "";
		for (int i=0; i<string.length(); i++) {
			string1 += c;
		}		
		return string1;
	}	
	
}
